package com.witframework.web.extremetable;

import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.toolbar.AbstractItem;
import org.extremecomponents.table.view.html.toolbar.ToolbarItem;
import org.extremecomponents.util.HtmlBuilder;

/**
 * @author wuxinyang
 * 修改<a href=""><img src=""></img></a>为<a href="" class=""></a>
 * 以使其可以支持换肤
 */
public class WsImageItem extends AbstractItem implements ToolbarItem {
    String image;
    String disabledImage;
    String alt;
    //是否使用<img>标签
    boolean useImgTag = true;
    String aTagStyleClass=null;
    String aTagDisableStyleClass=null;
    public WsImageItem(){
    	super();
    }
    public WsImageItem(boolean useImgTag,String aTagStyleClass,String aTagDisableStyleClass){
    	super();
    	this.useImgTag=useImgTag;
    	this.aTagStyleClass=aTagStyleClass;
    	this.aTagDisableStyleClass=aTagDisableStyleClass;
    }
    public String getDisabledImage() {
        return disabledImage;
    }

    public void setDisabledImage(String disabledImage) {
        this.disabledImage = disabledImage;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public void setImage() {

    }

    @Override
	public void disabled(HtmlBuilder html) {
    	if(useImgTag){
    		html.img().src(getDisabledImage()).style(getStyle()).alt(getAlt()).xclose();
    	}else{
    		html.append("<a ");
    		if(aTagDisableStyleClass!=null){
    			html.styleClass(aTagDisableStyleClass).xclose();
    		}
    		html.aEnd();
    	}
    }

    public String getAlt() {
        return alt;
    }

    public void setAlt(String alt) {
        this.alt = alt;
    }

    @Override
	public void enabled(HtmlBuilder html, TableModel model) {
        html.a();
        html.quote();
        html.append(getAction());
        html.quote();
        if(!useImgTag&&aTagStyleClass!=null){
        	html.styleClass(aTagStyleClass);
        }
        boolean showTooltips = model.getTableHandler().getTable().isShowTooltips();

        if (showTooltips) {
        	if(useImgTag){
        		html.close();
        		html.img().src(getImage()).style(getStyle()).title(getTooltip()).onmouseover(getOnmouseover()).onmouseout(getOnmouseout()).alt(getAlt()).xclose();
        	}else{
        		html.title(getTooltip()).close();
        	}
        } else {
        	if(useImgTag){
        		html.img().src(getImage()).style(getStyle()).onmouseover(getOnmouseover()).onmouseout(getOnmouseout()).alt(getAlt()).xclose();
        	}
        }

        html.aEnd();
    }
}
